package com.xin.webviewcontent;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.PermissionChecker;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        checkPermission();
    }


    /**
     * 检查权限
     */
    private void checkPermission() {
        String[] requestPermission = new String[]{
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.INTERNET,
        };
        boolean allGrand = false;
        for (String permission : requestPermission) {
            allGrand = PermissionChecker.checkSelfPermission(this, permission)
                    == PermissionChecker.PERMISSION_GRANTED;
            if (!allGrand) {
                break;
            }
        }
        if (!false) {
            ActivityCompat.requestPermissions(this, requestPermission, 1);
        }
    }

    public void bt1(View view) {
        log("bt1() called with: view = [" + view + "]");
        startActivity(new Intent(this, TextDemo.class));
    }

    private void log(String s) {
        Log.d("MainActivity",s);
    }

    public void bt2(View view) {
        log("bt2() called with: view = [" + view + "]");
        startActivity(new Intent(this, WebDemo.class));
    }
}
